﻿Imports TNCDAL
Imports System.Data.Linq
Imports System.Linq


Public Class CUnitCont
    Dim db As New TanNamChinhDataContext

    Public Function SelectAllRecordByID_Cont(ByVal ID_Cont As Integer) As IQueryable(Of tblUnitCont)
        Dim unitcont = From p In db.tblUnitConts
                       Where p.ID_Cont = ID_Cont
                    Select p

        Return unitcont
    End Function

    Public Function SelectRecordById(ByVal id As Integer) As tblUnitCont
        Dim unitcont = (From p In db.tblUnitConts
                 Where p.ID_UnitCont = id
                 Select p).Single
        Return unitcont
    End Function

    Public Sub Insert(ByVal obj As tblUnitCont)
        db.tblUnitConts.InsertOnSubmit(obj)
        db.SubmitChanges()
    End Sub

    Public Sub Update(ByVal obj As tblUnitCont)
        Dim unitcont = SelectRecordById(obj.ID_unitcont)
        unitcont.UnitGW = obj.UnitGW
        unitcont.UnitNW = obj.UnitNW
        unitcont.UnitPackage = obj.UnitPackage
        unitcont.ID_Unit = obj.ID_Unit
        db.SubmitChanges()
    End Sub

    Public Sub Delete(ByVal id As Integer)
        'Dim unitcont = SelectRecordById(id)
        'unitcont.IsActive = False
        'db.SubmitChanges()

        Dim unitcont = SelectRecordById(id)
        db.tblUnitConts.DeleteOnSubmit(unitcont)
        db.SubmitChanges()
    End Sub
End Class
